﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using GameSPK.Helpers;
using System.Windows.Controls;
using GameSPK.Model;
using GameSPK.DAO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows;

namespace GameSPK.Start
{
    class frmGioiThieuNguoiChoi: frmGenerel
    {
        private static frmGioiThieuNguoiChoi instance;
        private static object syncLock = new object();
        INguoiChoi nguoichoi;
        public static frmGioiThieuNguoiChoi getInstance(INguoiChoi nguoichoiinput)
        {
            if (instance == null)
            {
                lock (syncLock)
                {
                    if (instance == null)
                    {
                        instance = new frmGioiThieuNguoiChoi(nguoichoiinput);
                        
                    }
                }
            }

            return instance;
        }
        private frmGioiThieuNguoiChoi(INguoiChoi nguoichoiinput)
            : base()
        {
            nguoichoi = nguoichoiinput;
            this.Closed += new EventHandler(frmGioiThieuNguoiChoi_Closed);
            this.Loaded += new System.Windows.RoutedEventHandler(frmGioiThieuNguoiChoi_Loaded);
            AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)frmGioiThieuNguoiChoi_KeyDown);
            
        }
        void frmGioiThieuNguoiChoi_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
        }
        void frmGioiThieuNguoiChoi_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            Generate();
        }
        Button btnback;
        
        MediaElement mGioiThieu;
        private void Generate()
        {
            //back button
            btnback = new Button();
            btnback.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            btnback.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            LabelLayout lbloutback = TungNguoiChoiXMLDAO.getButtonBack();
            btnback.Margin = new System.Windows.Thickness(lbloutback.Left, lbloutback.Top, 0, 0);
            btnback.Height = lbloutback.Height;
            btnback.Width = lbloutback.Width;
            btnback.Visibility = System.Windows.Visibility.Visible;
            btnback.Name = "btnBack";
            ImageBrush myBrush = new ImageBrush();
            myBrush.ImageSource =
                   new BitmapImage(new Uri(ConfigXMLDAO.getBackButtonUrl(), UriKind.RelativeOrAbsolute));

            btnback.Background = myBrush;
            btnback.Click += new RoutedEventHandler(btnback_Click);
            gridMain.Children.Add(btnback);

            //video
            lbloutback = TungNguoiChoiXMLDAO.getLabel("Video");
            mGioiThieu = new MediaElement();
            mGioiThieu.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            mGioiThieu.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            mGioiThieu.Margin = new System.Windows.Thickness(lbloutback.Left, lbloutback.Top, 0, 0);
            mGioiThieu.Width = lbloutback.Width;
            mGioiThieu.Height = lbloutback.Height;
            mGioiThieu.Stretch = Stretch.Fill;
            mGioiThieu.Name = "mGioiThieu";
            mGioiThieu.LoadedBehavior = MediaState.Manual;
            mGioiThieu.Source = new Uri(nguoichoi.Video, UriKind.RelativeOrAbsolute);
            mGioiThieu.Play();
            gridMain.Children.Add(mGioiThieu);

            //ten
            lbloutback = TungNguoiChoiXMLDAO.getLabel("TenNguoiChoi");
            
            Label lblNguoiChoi = new Label();
            lblNguoiChoi.Name = "lblnguoichoi";
            lblNguoiChoi.Visibility = System.Windows.Visibility.Visible;
            lblNguoiChoi.Margin = new System.Windows.Thickness(lbloutback.Left, lbloutback.Top, 0, 0);
            lblNguoiChoi.Width = lbloutback.Width;
            lblNguoiChoi.Height = lbloutback.Height;
            lblNguoiChoi.Content = nguoichoi.TenNguoiChoi.Trim();
            DrawingBrush myDrawingBrush = new DrawingBrush();
            GeometryDrawing myGeometryDrawing = new GeometryDrawing();
            myGeometryDrawing.Brush = lbloutback.Background;

            myGeometryDrawing.Pen = new Pen(Brushes.Red, 1);
            GeometryGroup ellipses = new GeometryGroup();
            ellipses.Children.Add(new EllipseGeometry(new Point(25, 50), 12.5, 50));
            myGeometryDrawing.Geometry = ellipses;
            myDrawingBrush.Drawing = myGeometryDrawing;
            lblNguoiChoi.Background = myDrawingBrush;


            //lblNguoiChoi.Background = labelNguoichoi.Background;
            lblNguoiChoi.Foreground = lbloutback.Foreground;
            lblNguoiChoi.FontSize = lbloutback.FontSize;
            lblNguoiChoi.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
            lblNguoiChoi.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
            lblNguoiChoi.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblNguoiChoi.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            //lblNguoiChoi.FontFamily = new FontFamily("Tahoma");
            lblNguoiChoi.FontWeight = System.Windows.FontWeights.Bold;
            lblNguoiChoi.Style = (Style)this.FindResource("PulseLabel");
            
            gridMain.Children.Add(lblNguoiChoi); 

            //thong tin
            lbloutback = TungNguoiChoiXMLDAO.getLabel("ThongTin");

            Label lblThongTin = new Label();
            lblThongTin.Name = "lblthongtin";
            lblThongTin.Visibility = System.Windows.Visibility.Visible;
            lblThongTin.Margin = new System.Windows.Thickness(lbloutback.Left, lbloutback.Top, 0, 0);
            lblThongTin.Width = lbloutback.Width;
            lblThongTin.Height = lbloutback.Height;
            TextBlock noidung = new TextBlock();
            noidung.TextWrapping = TextWrapping.Wrap;
            noidung.Text = nguoichoi.ThongTin.Trim();
            lblThongTin.Content = noidung;
                

            lblThongTin.Background = lbloutback.Background;
            lblThongTin.Foreground = lbloutback.Foreground;
            lblThongTin.FontSize = lbloutback.FontSize;
            lblThongTin.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
            lblThongTin.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
            lblThongTin.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblThongTin.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            //lblNguoiChoi.FontFamily = new FontFamily("Tahoma");
            lblThongTin.FontWeight = System.Windows.FontWeights.Bold;
            lblThongTin.Style = (Style)this.FindResource("PulseLabel");

            gridMain.Children.Add(lblThongTin); 
            
        }

        void btnback_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        void frmGioiThieuNguoiChoi_Closed(object sender, EventArgs e)
        {
            instance = null;
        }

    }
}
